package com.zbkj.crmeb.handler.orderconfirm;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;

import com.alibaba.fastjson.JSON;

/**
 * @author: wsl
 * @date: 2024/2/22 0022 22:21
 * @ClassName: AbstractOrderConfirmHandler
 */
public abstract class AbstractOrderConfirmHandler implements OrderConfirmInterface{
    private static final Logger logger = LoggerFactory.getLogger(AbstractOrderConfirmHandler.class);

    @Override
    public boolean execute(OrderConfirmContext context){
        try {
            logger.info("execute入口:{}", JSON.toJSONString(context));
            boolean check = doPreCheck(context);
            if (!check){
                logger.error("订单确认后置逻辑校验失败");
                return false;
            }
            doHandler(context);
        }catch (Exception e){
            logger.error("处理订单确认后置逻辑异常:",e);
        }
        return true;

    }

    @Override
    public boolean doPreCheck(OrderConfirmContext context) {
        if (null == context){
            return false;
        }
        if (null == context.getStoreOrderInfo()){
            return false;
        }
        if (null == context.getPurchaseGoods()){
            return false;
        }
        return true;
    }
}
